package cn.growthgate.fgo.web.result;

import java.util.Collection;
import java.util.HashMap;

public class JsonResult extends HashMap<String, Object> {

	private static final long serialVersionUID = 2534107670518092932L;

	public static JsonResult ok() {
		JsonResult jsonResult = new JsonResult();
		jsonResult.put("state", "ok");
		return jsonResult;
	}

	public static JsonResult ok(String msg) {
		return ok("msg", msg);
	}

	public static JsonResult ok(Collection<?> list) {
		return ok("list", list);
	}

	public static JsonResult ok(Object data) {
		return ok("data", data);
	}

	public static JsonResult ok(String key, Object value) {
		return ok().set(key, value);
	}

	public static JsonResult fail() {
		JsonResult jsonResult = new JsonResult();
		jsonResult.put("state", "fail");
		return jsonResult;
	}

	public static JsonResult fail(String msg) {
		return fail("msg", msg);
	}

	public static JsonResult fail(String key, Object value) {
		return fail().set(key, value);
	}

	public JsonResult set(String key, Object value) {
		put(key, value);
		return this;
	}

}
